using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace FrameWork.BehaviourTree
{
    

    /// <summary>
    /// 选择节点
    /// </summary>
    public class Selector : Node
    {
        public Selector() : base()
        {
        }

        public Selector(List<Node> children) : base(children)
        {
        }

        public override NodeState Evaluate()
        {
            foreach (Node node in children)
            {
                switch (node.Evaluate())
                {
                    // 节点执行失败 跳过
                    case NodeState.FAILURE:
                        continue;
                    // 节点执行成功 返回当前
                    case NodeState.SUCCESS:
                        return state;
                    // 节点正在执行中 设置状态为 执行中  返回执行中
                    case NodeState.RUNNING:
                        state = NodeState.RUNNING;
                        return state;
                    default:
                        continue;
                }
            }

            // 默认为执行失败
            state = NodeState.FAILURE;
            return state;
        }
    }

}